﻿using AutoMapper;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;

namespace Business.WriteAPI.Application.Products
{
    public class PhotoAddRequestHandler : IRequestHandler<PhotoAddRequestModel, APIResult>
    {
        private IBaseRepository<ProductImg> productRepository;
        private readonly IMapper mapper;
        public PhotoAddRequestHandler(IBaseRepository<ProductImg> productRepository, IMapper mapper)
        {
            this.productRepository = productRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(PhotoAddRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.AddSuccess;
            result.Msg = "新增成功";

            ProductImg product = mapper.Map<ProductImg>(request);

            productRepository.Add(product);


            return Task.FromResult(result);
        }
    }
    public class PhotoAddRequestModel:IRequest<APIResult>
    {
        public string ImgUrl { get; set; }
    }
}
